<?php
include "strings.php";
class uSSKString extends SSKString {
	protected $value = null;
	private $enc = 'UTF-8';
	
	public function __construct($value = null) {
		$encvalue=mb_convert_encoding($value, $this->enc);
		parent::__construct($encvalue);
	}
	public function __invoke($value = null) {
		$encvalue=mb_convert_encoding($value, $this->enc);
		parent::__invoke($encvalue);
	}
	public function Append($append) {
		$encstr=mb_convert_encoding($append, $this->enc);
		parent::Append($encstr);
	}
	public function toArray() {
		if($this->value) {
			$end=mb_strlen($this->value, $this->enc);
			$charr=array();
			for( $idx = 0; $idx < $stop; $idx++) {
				$charr[]=mb_substr($string, $idx, 1);
			}
			return $charr;
		} else {
			return "";
		}
	}
	public function Length() {
		$strlen=mb_strlen($this->value, $this->enc);
		return $strlen;
	}
	public function Substring($start, $length=null) {
		if($this->value) {
			if(!$length) {
				$length=mb_strlen($this->value);
			}
			$substr=mb_substr($this->value, $start, $length, $this->enc);
			return $substr;
		} else {
			return "";
		}
	}
	public function toLower() {
		$this->value=mb_strtolower($this->value, $this->enc);
	}
	public function toUpper() {
		$this->value=mb_strtoupper($this->value, $this->enc);
	}
	//TODO: fare Compare() multibyte safe.
	public function Compare($string, $caseinsensitive = false, $length = null) {
		echo 'WARNING: '.__CLASS__.'::'.__METHOD__.' is not multibyte safe yet.';
		parent::Compare($string, $caseinsensitive, $length);
	}
	//TODO: fare Trim() multibyte safe.
	public function Trim($charlist=null) {
		echo 'WARNING: '.__CLASS__.'::'.__METHOD__.'() is not multibyte safe yet.';
		parent::Trim($charlist);
	}
	//TODO: fare Explode() multibyte safe.
	public function Explode($delimiter, $limit=null) {
		echo 'WARNING: '.__CLASS__.'::'.__METHOD__.'() is not multibyte safe yet.';
		parent::Explode($delimiter, $limit);
	}
	//TODO: fare Implode() multibyte safe.
	public function Implode($pieces, $glue=null) {
		echo 'WARNING: '.__CLASS__.'::'.__METHOD__.'() is not multibyte safe yet.';
		parent::Implode($pieces, $glue);
	}
	//TODO: fare Split() multibyte safe.
	public function Split($limit) {
		echo 'WARNING: '.__CLASS__.'::'.__METHOD__.'() is not multibyte safe yet.';
		parent::Split($limit);
	}
	public function getEncoding() {
		return $this->enc;
	}
	public function setEncoding($encoding) {
		mb_convert_encoding($encoding, $this->value, $this->enc);
		$this->enc=$encoding;
	}
}
?>